// 引入路由组件
// import Home from '@/pages/Home'
import Register from '@/pages/Register'
import Search from '@/pages/Search'
import Pagination from '@/components/Pagination'
import Detail from '@/pages/Detail'
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCar from '@/pages/ShopCart'
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess'
import Center from '@/pages/Center'
// center子组件
import MyOrder from '@/pages/Center/myOrder'
import GroupOrder from '@/pages/Center/groupOrder'

// 引入store
// import store from '@/store'

// 路由routes配置信息
export default [
  // 首页
  {
    path: "/home",
    // 路由懒加载
    component: () => import('@/pages/Home'),
    meta: { show: true }
  },
  // 登陆页
  {
    path: "/login",
    // 同上
    component: () => import('@/pages/Login'),
    meta: { show: false }
  },
  // 注册页
  {
    path: "/register",
    component: Register,
    meta: { show: false }
  },
  // 搜索栏
  {
    // :keyWord属于params传参中的路由占位
    name: "search",
    // 占位符后加?表示params参数可传递也可不传递
    path: "/search/:keyword?",
    component: Search,
    meta: { show: true },
    // 布尔值写法
    // props: true
    // 对象写法
    // props: {
    //   a: 1,
    //   b: 2
    // }
    // 函数写法
    // props: ($route) => {
    //   return {
    //     keyWord: $route.params.keyWord,
    //     k: $route.query.k
    //   }
    // }
  },
  // 详情页组件
  {
    name: "Detail",
    path: '/detail/:skuId',
    component: Detail,
    meta: { show: true }
  },
  // 分页器组件
  {
    name: "pagination",
    path: '/pagination',
    component: Pagination
  },
  // 添加购物车页
  {
    name: "AddCartSuccess",
    path: '/addCartSuccess',
    component: AddCartSuccess,
    meta: { show: true }
  },
  // 购物车列表页
  {
    name: "ShopCart",
    path: '/shopCart',
    meta: { show: true },
    component: ShopCar
  },
  // 订单信息页
  {
    name: 'trade',
    path: '/trade',
    meta: { show: true },
    component: Trade,
    beforeEnter: (to, from, next) => {
      // 页面从购物车页跳转到交易页才可以放行
      if (from.path == '/shopCart') {
        next();
      } else {
        next(from.path);
      }
    }
  },
  // 交易页面
  {
    name: 'pay',
    path: '/pay',
    meta: { show: true },
    component: Pay,
    // 只能从交易页跳转到支付页
    beforeEnter: (to, from, next) => {
      if (from.path == '/trade') {
        next();
      } else {
        next(from.path)
      }
    }
  },
  // 交易成功页面
  {
    name: 'paySuccess',
    path: '/paySuccess',
    meta: { show: true },
    component: PaySuccess,
    beforeEnter: (to, from, next) => {
      if (from.path == '/pay') {
        next();
      } else {
        next(from.path)
      }
    }
  },
  // 个人中心页
  {
    name: 'center',
    path: '/center',
    meta: { show: true },
    component: Center,
    children: [
      {
        path: 'myOrder',
        component: MyOrder,
        meta: { show: true }
      },
      {
        path: 'groupOrder',
        component: GroupOrder,
        meta: { show: true }
      },
      // 子路由组件的重定向
      {
        path: '/center',
        redirect: '/center/myOrder'
      }
    ]
  },
  // 重定向，在项目运行访问/默认路由时，让他重新定位到首页/home
  {
    path: "*",
    redirect: "/home"
  },

  // 组件通信深入
  {
    path: '/communication',
    component: () => import('@/pages/Communication/Communication'),
    children: [
      {
        path: 'event',
        component: () => import('@/pages/Communication/EventTest/EventTest'),
        meta: {
          isHideFooter: true
        },
      },
      {
        path: 'model',
        component: () => import('@/pages/Communication/ModelTest/ModelTest'),
        meta: {
          isHideFooter: true
        },
      },
      {
        path: 'sync',
        component: () => import('@/pages/Communication/SyncTest/SyncTest'),
        meta: {
          isHideFooter: true
        },
      },
      {
        path: 'attrs-listeners',
        component: () => import('@/pages/Communication/AttrsListenersTest/AttrsListenersTest'),
        meta: {
          isHideFooter: true
        },
      },
      {
        path: 'children-parent',
        component: () => import('@/pages/Communication/ChildrenParentTest/ChildrenParentTest'),
        meta: {
          isHideFooter: true
        },
      },
      {
        path: 'scope-slot',
        component: () => import('@/pages/Communication/ScopeSlotTest/ScopeSlotTest'),
        meta: {
          isHideFooter: true
        },
      }
    ],
  }

]
